home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / Library / Manuels & Misc / Assembly / AOA.ZIP / CH16 / TESTPRE.ASM < prev   
Encoding:
Assembly Source File  |  1994-07-09  |  1.8 KB  |  107 lines

  1.         .xlist
  2.         include     stdlib.a
  3.         includelib    stdlib.lib
  4.         .list
  5.  
  6. dseg        segment    para public 'data'
  7.  
  8. String1        byte    "Hello there, how are you?",0
  9. String2        byte    "Hi there, how are you?",0
  10.  
  11. dseg        ends
  12.  
  13.  
  14. cseg        segment    para public 'code'
  15.         assume    cs:cseg, ds:dseg
  16.  
  17.  
  18.  
  19.  
  20. MatchPre    proc    far        ;Must be far!
  21.         push    bp
  22.         mov    bp, sp
  23.         push    ax
  24.         push    ds
  25.         push    si
  26.         push    di
  27.  
  28.         lds    si, 2[bp]    ;Get the return address.
  29. CmpLoop:    mov    al, ds:[si]    ;Get string to match.
  30.         cmp    al, 0        ;If at end of prefix,
  31.         je    Success        ; we succeed.
  32.         cmp    al, es:[di]    ;See if it matches prefix,
  33.         jne    Failure        ; if not, immediately fail.
  34.         inc    si
  35.         inc    di
  36.         jmp    CmpLoop
  37.  
  38. Success:    add    sp, 2        ;Don't restore di.
  39.         inc    si        ;Skip zero terminating byte.
  40.         mov    2[bp], si    ;Save as return address.
  41.         pop    si
  42.         pop    ds
  43.         pop    ax
  44.         pop    bp
  45.         stc            ;Return success.
  46.         ret
  47.  
  48. Failure:        inc    si        ;Need to skip to zero byte.
  49.         cmp    byte ptr ds:[si], 0
  50.         jne    Failure
  51.         inc    si
  52.         pop    di
  53.         mov    2[bp], si    ;Save as return address.
  54.         pop    si
  55.         pop    ds
  56.         pop    ax
  57.         pop    bp
  58.         clc            ;Return failure.
  59.         ret
  60. MatchPre    endp
  61.  
  62.  
  63. Main        proc
  64.         mov    ax, dseg
  65.         mov    ds, ax
  66.         mov    es, ax
  67.  
  68.         meminit
  69.  
  70.         lesi    String1
  71.         call    MatchPre
  72.         byte    "Hello",0
  73.         jc    Success1
  74.         print
  75.         byte    "String1 does not begin with 'Hello'",cr,lf,0
  76.         jmp    Try2
  77.  
  78. Success1:    print
  79.         byte    "String1 begins with 'Hello'",cr,lf,0
  80.  
  81. Try2:        lesi    String2
  82.         call    MatchPre
  83.         byte    "Hello",0
  84.         jc    Success2
  85.         print
  86.         byte    "String2 does not begin with 'Hello'",cr,lf,0
  87.         jmp    Quit
  88.  
  89. Success2:    print
  90.         byte    "String2 begins with 'Hello'",cr,lf,0
  91.  
  92.  
  93.  
  94. Quit:        ExitPgm
  95. Main        endp
  96.  
  97. cseg            ends
  98.  
  99. sseg        segment    para stack 'stack'
  100. stk        db    1024 dup ("stack   ")
  101. sseg        ends
  102.  
  103. zzzzzzseg    segment    para public 'zzzzzz'
  104. LastBytes    db    16 dup (?)
  105. zzzzzzseg    ends
  106.         end    Main
  107.